<template>
	<div class="form-container" style="padding-top: 0px !important;">
		<exAddEdit ref="exAddEdit" v-model="model"></exAddEdit>

		<div style="display: block;text-align: center;">
			<el-button v-if="isAdd" @click="resetThisVal('model')">{{comLan["btnReset"]}}</el-button>
			<el-button @click="closeCurrent">{{comLan["btnCancel"]}}</el-button>
			<el-button type="primary" @click="save" :loading="loading">{{comLan["btnSave"]}}</el-button>
		</div>
	</div>
</template>

<script>
	import common from "@/common/common.js";
	import js from "./js.js";
	import exAddEdit from "@/Auto/Organization/OrganizationAddEdit.vue";

	export default {
		name: "OrganizationAddRedict",
		components: {
			exAddEdit
		},
		mixins: [common.baseVM, js],
		data() {
			return {
				model: {
					OrganizationID: 0,
					HeaderUrl: null,
					Name: null,
					Phone: null,
					Address: null,
					EnumStatus: 1,
					Pwd: null,
					Remark: null,
				}
			}
		},
		methods: {
			init() {
				this.loadBeforeValSuccess = false;
				this.resetVal("model");
				var query = this.getQuery();
				var id = parseInt(query["id"]);
				if (isNaN(id)) id = 0;
				this.isAdd = id == 0;
				if (this.isAdd) { //新建
					this.loadBeforeVal();
					return;
				}
				this.get("api/Organization/Get?id=" + id).then(data => {
					this.model = data.Result;
				});
			},
			closeCurrent() {
				this.refreshList("/Organization/OrganizationList");
			},
			save() {
				this.$refs.exAddEdit.formValidate('formModel', () => {
					var post = JSON.parse(JSON.stringify(this.model));
					this.loading = true;
					this.post('api/Organization/Save', post).then(data => {
						this.showToast(data.Message, "success");
						this.loading = false;
						
						this.clearBeforeVal();
						this.closeCurrent();
					}).catch((error) => {
						this.loading = false;
					});
				});
			}
		}
	}
</script>
